/*
 * Copyright (c) 2010 Philip Foulkes <philip.foulkes@gmail.com>
 *
 * This file is free software and is made available under the 
 * terms of the GNU General Public License, version 2, or at your
 * option, any later version
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef _MSRP_H_
#define _MSRP_H_

#ifdef __KERNEL__
#define uint8 	u8
#define uint16 	u16
#define uint32 	u32
#endif

#include "msrp_attribute_values.h"

/* ============================================================================================================ */
/* ============================================================================================================ */
struct msrp_register_stream
{
	uint8 stream_id [8];
	int declaration_type;
	struct msrp_data_frame_parameters msrp_data_frame_parameters;
	struct msrp_tspec msrp_tspec;
	struct msrp_priority_and_rank msrp_priority_and_rank;
	uint32 accumulated_latency;
};

struct msrp_deregister_stream
{
	uint8 stream_id [8];
};

struct msrp_register_attach
{
	uint8 stream_id [8];
	int declaration_type;
};

struct msrp_deregister_attach
{
	uint8 stream_id [8];
};

/* =========================================================================== */
struct msrp_read_data
{
	int command;
};

/* command numbers */
#define COMMAND_NUMBER_MIN									1
#define COMMAND_NUMBER_REGISTER_ATTACH_INDICATION			1
#define COMMAND_NUMBER_DEREGISTER_ATTACH_INDICATION		 	2
#define COMMAND_NUMBER_REGISTER_STREAM_INDICATION			3
#define COMMAND_NUMBER_DEREGISTER_STREAM_INDICATION		 	4
#define COMMAND_NUMBER_MAX									4
/* =========================================================================== */

#define MSRP_IOC_MAGIC 0xF1
/*
 * S means "Set" through a ptr,
 * G means "Get": reply by setting through a pointer
 */
#define MSRP_IOC_S_REGISTER_STREAM				_IOW(MSRP_IOC_MAGIC,0,struct msrp_register_stream)
#define MSRP_IOC_S_DEREGISTER_STREAM			_IOW(MSRP_IOC_MAGIC,1,struct msrp_deregister_stream)

#define MSRP_IOC_S_REGISTER_ATTACH				_IOW(MSRP_IOC_MAGIC,2,struct msrp_register_attach)
#define MSRP_IOC_S_DEREGISTER_ATTACH			_IOW(MSRP_IOC_MAGIC,3,struct msrp_deregister_attach)

#define MSRP_IOC_MAXNR 3
/* ============================================================================================================ */
/* ============================================================================================================ */

#define MSRP_DECLARATION_TYPE_ADVERTISE		1
#define MSRP_DECLARATION_TYPE_FAILED		2
#define MSRP_DECLARATION_TYPE_ASKING_FAILED	3
#define MSRP_DECLARATION_TYPE_READY		4
#define MSRP_DECLARATION_TYPE_READY_FAILED	5

#ifdef __KERNEL__

/**
*   Internal state variables
*/
#define MSRP_PORT_MEDIA_TYPE_ACCESS_CONTROL_PORT			1
#define MSRP_PORT_MEDIA_TYPE_NON_DMN_SHARED_MEDIUM_PORT 	2

#define MSRP_DIRECTION_TALKER		1
#define MSRP_DIRECTION_LISTENER		2

#define MSRP_WIRE_PROPAGATION_TIME_DEFAULT 500 /* nano seconds */

struct msrp;
struct mmrp;
struct mvrp;

typedef int (*msrp_register_attach_indication)   (u8 stream_id[8], int declaration_type);
typedef int (*msrp_deregister_attach_indication) (u8 stream_id[8]);
typedef int (*msrp_register_stream_indication) 	 (u8 stream_id[8], int declaration_type, struct msrp_data_frame_parameters * msrp_data_frame_parameters, struct msrp_tspec * msrp_tspec, struct msrp_priority_and_rank * msrp_priority_and_rank, u32 accumulated_latency);
typedef int (*msrp_deregister_stream_indication) (u8 stream_id[8]);

struct msrp_ops
{
	msrp_register_attach_indication 		msrp_register_attach_indication;
	msrp_deregister_attach_indication 		msrp_deregister_attach_indication;
	msrp_register_stream_indication 		msrp_register_stream_indication;
	msrp_deregister_stream_indication		msrp_deregister_stream_indication;
};

struct msrp
{
	struct mrp mrp; /* this has to the the first member */
	
	struct msrp_ops * msrp_ops;
	
	struct cdev cdev;
	int cdev_init;
	int dev_t_used;
	
	struct completion completion;
	
	struct list_head msrp_read_data_list;
	spinlock_t msrp_read_data_list_lock;
	
	char * port_name;
};

void msrp_register (struct msrp_ops * msrp_ops);

int msrp_register_attach_request 	(u8 stream_id [8], int declaration_type);
int msrp_deregister_attach_request 	(u8 stream_id [8]);
int msrp_register_stream_request 	(u8 stream_id [8], int declaration_type, struct msrp_data_frame_parameters * msrp_data_frame_parameters, struct msrp_tspec * msrp_tspec, struct msrp_priority_and_rank * msrp_priority_and_rank, u32 accumulated_latency);
int msrp_deregister_stream_request 	(u8 stream_id [8]);

#endif

#endif
